package com.liyujie.networkrequest.remotedata;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;
import com.liyujie.networkrequest.mobile.ResultEntity;
import com.liyujie.networkrequest.utils.InitializeUtils;

import io.reactivex.observers.DisposableObserver;

public abstract class InterceptObserver<T> extends DisposableObserver<ResultEntity<T>> implements IObserver {

    @Override
    public void onComplete() {

    }

    @Override
    public void onNext(ResultEntity<T> tResultEntity) {
        switch (tResultEntity.status){
            case 200:
                onNextData(tResultEntity);
                break;
            default:
                onErrorNet(null,tResultEntity.msg);
                break;
        }
    }


    @Override
    public void onError(Throwable e) {
        onErrorNet(null,e.getMessage());
        LogUtils.d(e.getMessage());
    }


    @Override
    public boolean isShowToast() {
        return true;
    }


    @Override
    public void onFinish() {
        LogUtils.d("onFinish");
    }


    @Override
    public void onDataEmpty(@Nullable String netMsg) {
        InitializeUtils.getDefaultMaker().show(netMsg);
    }


    @Override
    public void onNoData(@Nullable String netMsg) {
        LogUtils.d(netMsg);
    }
}
